package com.hero.take.entity.result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: qianshengqiang
 * @date: 2021/4/2 4:37 下午
 */
@Data
public class BasePageResponse<T> {

    private Long page;
    private Long size;
    private Long count;
    private Long totalPage;
    private List<T> list;
    private Object totalData;

    public long getTotalPage() {
        return count == 0 ? 0 : (count - 1) / size + 1;
    }


    public BasePageResponse(Page<T> page) {
        this.page = page.getCurrent();
        this.size = page.getSize();
        this.count = page.getTotal();
        this.totalPage = page.getPages();
        this.list = page.getRecords();
    }

    public BasePageResponse(Page page, List<T> list) {
        this.list = list;
        this.page = page.getCurrent();
        this.size = page.getSize();
        this.count = page.getTotal();
        this.totalPage = page.getPages();
    }

    public BasePageResponse(Page page, List<T> list, Object totalData) {
        this.list = list;
        this.page = page.getCurrent();
        this.size = page.getSize();
        this.count = page.getTotal();
        this.totalPage = page.getPages();
        this.totalData = totalData;
    }

    public BasePageResponse() {
        this.page = 1L;
        this.size = 10L;
        this.count = 0L;
        this.totalPage = 0L;
        this.list = new ArrayList<>();
    }

}
